#!/bin/bash

# Find the process ID (PID) of the Node.js server
PID=$(ps aux | grep 'node server.js' | grep -v grep | awk '{print $2}')

if [ -z "$PID" ]; then
  echo "Node.js server is not running."
else
  echo "Stopping Node.js server with PID: $PID"
  kill $PID

  # Optionally, wait for the process to terminate and confirm
  sleep 2
  if ps -p $PID > /dev/null; then
    echo "Force killing the Node.js server."
    kill -9 $PID
  else
    echo "Node.js server stopped successfully."
  fi
fi
